package com.tinem.platform.web.auth.login.code;

import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.SpringSecurityCoreVersion;

import java.util.Collection;

/**
 * @author fzh
 */
@Data
@EqualsAndHashCode(callSuper=false)
public class CodeAuthenticationToken extends AbstractAuthenticationToken {

	private static final long serialVersionUID = SpringSecurityCoreVersion.SERIAL_VERSION_UID;

	private final Object principal;
	private String countryMobileCode;
	private String to;
	private String code;
	private Long codeId;

	public CodeAuthenticationToken(String countryMobileCode,String to,String code,Long codeId) {
		super(null);
		this.countryMobileCode=countryMobileCode;
		this.principal = countryMobileCode+to;
		this.to=to;
		this.code = code;
		this.codeId = codeId;
		setAuthenticated(false);
	}

	public CodeAuthenticationToken(Object to, Collection<? extends GrantedAuthority> authorities) {
		super(authorities);
		this.principal = to;
		super.setAuthenticated(true);
	}

	@Override
	public Object getPrincipal() {
		return this.principal;
	}
	
	@Override
	public Object getCredentials() {
		return null;
	}

	@Override
	public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException {
		super.setAuthenticated(isAuthenticated
		);
	}

	@Override
	public void eraseCredentials() {
		super.eraseCredentials();
	}

}